function success(str) {
    ZENG.msgbox.show(str, 4, 1000);
}
function error(str) {
    ZENG.msgbox.show(str, 5, 2000);
}
function load(str) {
    ZENG.msgbox.show(str, 6, 20000000000000000000);
}
function msghidden() {
    $("#q_Msgbox").fadeOut();
}
/*弹出窗口模态*/
function openDialog(url, title) {
    //art.dialog.open(url, {title: title, lock: true});
    var artDialog = dialog({
        id:"AULA_DIALOG",
        url: url,
        title: title,
        zIndex: 9999
    }).showModal();
}
var _layerModal = null;
/*Layer 弹出窗口*/
function layerModal(url, title,_w,_h){
    var _layerModal = layer.open({
          type: 2,
          title: title,
          shadeClose: true,
          shade: 0.8,
          area: [_w, _h],
          content: url //iframe的url
        });
}
/*Layer 关闭弹出窗口*/
function closeLayerModal(){
    layer.closeAll();
}
// console.log(layer)

/*异步提交表单数据*/
$(".submit-ajax").on("click",function(){
    var _this = $(this);
    if(_this.hasClass('disabled')){
        return false;
    }
    var _form = $(_this.attr('data-form'));
    _this.addClass('disabled');
    $.post(_form.attr('action'),_form.serialize(),function(rel){
        _this.removeClass('disabled');
        if(rel.code>0){
            if(rel.msg!=''){
                success(rel.msg);
            }
        }else{
            error(rel.msg);
        }
        if(rel.url != '' && rel.url != undefined){
            setTimeout(function(){
                if(rel.url == '/reload'){
                    top.location.reload();
                }else{
                    location.href = rel.url;
                }
            },2000);
        }
    },'json');
})
/*异步删除数据*/
$(".delete").on("click",function(){
    var _this = $(this);
    if(_this.hasClass('disabled')){
        return false;
    }
    if(_this.hasClass('confirm')){
        if(!confirm(_this.data('rel'))) return false;
    }
    var ids = null;
    var data = {};
    if(_this.hasClass('more-checkbox')){
        ids = get_checkbox_value();
        if(ids == '' || ids == null){ error('请选择数据.');return false;}
        data = {ids:ids}
    }
    _this.addClass('disabled');
    $.post(_this.data('action'),data,function(rel){
        _this.removeClass('disabled');
        if(rel.code>0){
            if(rel.msg!=''){
                success(rel.msg);
            }
        }else{
            error(rel.msg);
        }
        if(rel.url != ''){
            setTimeout(function(){
                if(rel.url == '/reload'){
                    location.reload();
                }else{
                    location.href = rel.url;
                }
            },2000);
        }
    });
})
/*异步删除数据*/
$(".ajax-switch").on("click",function(){
    var _this = $(this);
    if(_this.hasClass('disabled')){
        return false;
    }
    var status = $(_this).prop('checked') ? 1 : 0;
    _this.addClass('disabled');
    $.post(_this.data('action'),{"status":status},function(rel){
        _this.removeClass('disabled');
        if(rel.code>0){
            if(rel.msg!=''){
                success(rel.msg);
            }
        }else{
            error(rel.msg);
        }
        if(rel.url != ''){
            setTimeout(function(){
                if(rel.url == '/reload'){
                    location.reload();
                }
            },2000);
        }
    });
})
/*异步删除数据*/
$(".ajax-change").on("blur",function(){
    var _this = $(this);
    if(_this.hasClass('disabled')){
        return false;
    }
    var val = $(_this).val();
    _this.addClass('disabled');
    $.post(_this.data('action'),{"val":val},function(rel){
        _this.removeClass('disabled');
        if(rel.code>0){
            if(rel.msg!=''){
                success(rel.msg);
            }
        }else{
            error(rel.msg);
        }
        if(rel.url != ''){
            setTimeout(function(){
                if(rel.url == '/reload'){
                    //location.reload();
                }else{
                    //location.href = rel.url;
                }
            },2000);
        }
    });
})
/*批量选择*/
$(".all-checkbox").click(function(){
    var _this = $(this);
    var checkbox = $(".checkbox");
    if(_this.prop('checked')){
        for (var k=0;k<checkbox.length;k++) {
            if($(checkbox[k]).prop('disabled')) continue;
            $(checkbox[k]).prop('checked',true);
        }
    }else{
        for (var k=0;k<checkbox.length;k++) {
            if($(checkbox[k]).prop('disabled')) continue;
            $(checkbox[k]).prop('checked',false);
        }
    }

})
function insertAtCaret(textObj, textValue) {
        if (document.all && textObj.createTextRange && textObj.caretPos) {
            var caretPos = textObj.caretPos;
            caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ?
            textValue + '' : textValue;
        } else if (textObj.setSelectionRange) {
            var rangeStart = textObj.selectionStart;
            var rangeEnd = textObj.selectionEnd;
            var tempStr1 = textObj.innerHTML.substring(0, rangeStart);
            var tempStr2 = textObj.innerHTML.substring(rangeEnd);
            textObj.innerHTML = tempStr1 + textValue + tempStr2;
            textObj.focus();
            var len = textValue.length;
            textObj.setSelectionRange(rangeStart + len, rangeStart + len);
            textObj.blur();
        } else {
            textObj.innerHTML += textValue;
     }
 }
 /*获取到批量选择的checkebox值*/
 function get_checkbox_value(){
    var checkbox = $(".checkbox");
    var str = '';
    for (var k=0;k<checkbox.length;k++) {
        if($(checkbox[k]).prop('disabled')) continue;
        if($(checkbox[k]).prop('checked')){
            str += str == '' ? $(checkbox[k]).val() : '`'+$(checkbox[k]).val();
        }
    }
    return str;
 }